package cn.zhouchao.system.controller;

import cn.zhouchao.basic.util.AjaxResult;
import cn.zhouchao.basic.util.PageList;
import cn.zhouchao.system.domain.Systemdictionarydetail;
import cn.zhouchao.system.query.SystemdictionarydetailQuery;
import cn.zhouchao.system.service.ISystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/sdd")
public class SystemdictionarydetailController {
    @Autowired
    private ISystemdictionarydetailService service;
    //查询全部数据类型
    @GetMapping
    public List<Systemdictionarydetail> findAll(){
        return service.findAll();
    }

    //根据id查询数据类型
    @GetMapping("/{id}")
    public Systemdictionarydetail findById(@PathVariable("id") Long id){
        return service.findById(id);
    }

    // 新增数据类型
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemDictionaryDetail){
        if(null==systemDictionaryDetail.getId()){
            service.add(systemDictionaryDetail);
        }else {
            service.update(systemDictionaryDetail);
        }
        return new AjaxResult().success();
    }

    // 删除数据类型
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id){
        service.delete(id);
        return new AjaxResult().success();
    }

    // 批量删除数据类型
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        service.batchDelete(ids);
        return new AjaxResult().success();
    }

    // 分页
    @PostMapping
    public PageList<Systemdictionarydetail> pageQuery(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
        return service.queryByPage(systemdictionarydetailQuery);
    }

    // 抽屉
    @GetMapping("/drawer/{id}")
    public List<Systemdictionarydetail> findDetail(@PathVariable Long id){
        List<Systemdictionarydetail> details = service.findDetail(id);
        return details;
    }

}
